package com.summer.JUnit;

import java.lang.ref.WeakReference;  

import junit.framework.TestCase;

public class TestJUnit extends TestCase {

	/**
	 * 测试小数，需要指明位数*/
	public void testDecimals(){
		assertEquals("Should be 3 1/3", 3.333 , 10.0/3.0,0.001);
	}
	
	/**
	 * 测试是否为空*/
	public void testNull(){
//		assertNull("给定一个为NULL的值则成功",new Object());
//		assertNull("给定一个为NULL的值则成功",new Object[0]);
		assertNull("给定一个为NULL的值则成功",null);
//		assertNotNull(new Object());
//		assertNotNull(new Object[0]);
	}
	
	/**
	 * 测试是否相同*/
	public void testSame(){
//		assertSame(new Object(),new Object());
		Object obj = new Object();
//		assertSame(obj,obj);
		WeakReference<Object> weakObj = new WeakReference<Object>(obj);
		assertSame(obj,weakObj.get());
	}
	
	/**
	 * 关于性能方面的测试
	 * 可以是用JUnitPerf模拟高负荷测试*/
	public void testPerformance(){
		long timerStart = System.currentTimeMillis();
		
		try {
			Thread.sleep(998);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		long timerEnd = System.currentTimeMillis();
		
		assertTrue((timerEnd - timerStart)/1000 < 1.0);
	}
}
